package com.dy.nygl.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dy.nygl.mapper.UserMapper;
import com.dy.nygl.pojo.User;
import com.dy.nygl.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Resource(name = "userDao")
	private UserMapper userDao;

	@Override
	public User checkUser(String account) {
		System.out.println("checkUser--------->");
		User user = userDao.selectUserByAccount(account);
		if (user != null) {
			System.out.println("getUser:" + user);
			return user;
		} else {
			System.out.println("userΪ��");
		}
		return null;
	}

	public User login(String account, String password) {
		System.err.println("login------------->");
		User user = userDao.selectUser(account, password);
		if (user != null) {
			System.err.println("user����null");
			return user;
		}
		System.err.println("user��null");
		return null;
	}

	@Override
	public int updateUser(User userSubmit) {
		User user = new User();
		user.setAccount(userSubmit.getAccount());
		user.setIdentity(userSubmit.getIdentity());
		user.setMailbox(userSubmit.getMailbox());
		user.setName(userSubmit.getName());
		user.setPassword(userSubmit.getPassword());
		user.setId(userSubmit.getId());
		userDao.updateByPrimaryKeySelective(user);
		return 1;
	}

	@Override
	public List<User> selectAll() {
		List<User> list = userDao.selectAll();
		return list;
	}

	@Override
	public boolean deleteUser(Integer id) {
		int i = userDao.deleteByPrimaryKey(id);
		if (i > 0) {
			return true;
		}
		return false;
	}

	@Override
	public User selectOne(int id) {
		User user = userDao.selectByPrimaryKey(id);
		return user;
	}

	@Override
	public User selectUserByName(String name) {
		User user = userDao.selectUserByAccount(name);
		return user;
	}

}
